/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import com.sun.faces.util.CollectionsUtils;
import java.util.HashMap;
import javax.faces.context.FacesContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Neo
 */
public class Cookies {

    public static HashMap<String, String> getCookies() {
        HashMap<String, String> hm = new HashMap<String, String>();
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        Cookie[] ck = request.getCookies();
        for (int i = 0; i < ck.length; i++) {
            hm.put(ck[i].getName(), ck[i].getValue());
        }
        return hm;
    }
    
    public static void add(String name, String value){
        HttpServletResponse respond = (HttpServletResponse)  FacesContext.getCurrentInstance().getExternalContext().getResponse();
        Cookie ck = new Cookie(name, value);
        respond.addCookie(ck);
    }
}
